import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';

class Tucao extends StatefulWidget {
  Tucao({Key key}) : super(key: key);

  _TucaoState createState() => _TucaoState();
}

class _TucaoState extends State<Tucao> {
  int _groupValue = 0;

  List imgList = new List<File>();
  Future getImage() async {
    var image = await ImagePicker.pickImage(source: ImageSource.gallery);
    setState(() {
      if(image != null){
        imgList.add(image);
      }
    });
  }

  var _content;

  dynamic getBody() {
    if (showLoadingDialog()) {
      // return getProgressDialog();
    } else {
      return getListView();
    }
  }

  bool showLoadingDialog() {
    if (imgList.length == null) {
      return true;
    }

    return false;
  }

  // Center getProgressDialog() {
  //   return new Center(child: new CircularProgressIndicator());
  // }

  ListView getListView() => new ListView.builder(
      scrollDirection: Axis.horizontal,
      itemCount: imgList.length,
      itemBuilder: (BuildContext context, int position) {
        return Stack(
          children: <Widget>[
            Image.file(
              imgList[position],
              width: 90,
            ),
            InkWell(
              child: Container(
                margin: EdgeInsets.fromLTRB(70, 0, 0, 0),
                child: Text('X',
                    style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 18,
                        color: Color.fromRGBO(220, 220, 220, 1))),
              ),
              onTap: () {
                setState(() {
                 imgList.removeAt(position);
                });
              },
            )
          ],
        );
      });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('我要吐槽'),
        centerTitle: true,
      ),
      body: Stack(
        children: <Widget>[
          Container(
            //底
            width: 360,
            decoration: BoxDecoration(color: Color.fromRGBO(242, 242, 242, 1)),
          ),
          Column(
            children: <Widget>[
              Stack(
                children: <Widget>[
                  Container(
                    width: 360,
                    height: 250,
                    decoration: BoxDecoration(color: Colors.white),
                  ),
                  Container(
                    width: 340,
                    margin: EdgeInsets.fromLTRB(10, 20, 0, 0),
                    child: TextField(
                      maxLines: 3,
                      decoration: InputDecoration(
                        hintText: '请写下你的意见或建议',
                        border: OutlineInputBorder(),
                      ),
                      onChanged: (value){
                        _content = value;
                      },
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(10, 130, 0, 0),
                    child: Row(
                      children: <Widget>[
                        Container(
                          child: InkWell(
                            child: Image.asset('images/upload.png',
                                width: 90, height: 90),
                            onTap: getImage,
                          ),
                        ),
                        Container(
                          width: 250,
                          height: 60,
                          color: Colors.white,
                          child: getBody(),
                        )
                      ],
                    ),
                  )
                ],
              ),
            ],
          ),
          Container(
            height: 90,
            width: 370,
            margin: EdgeInsets.fromLTRB(0, 260, 0, 0),
            decoration: BoxDecoration(color: Colors.white),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: <Widget>[
                Container(
                  margin: EdgeInsets.fromLTRB(10, 10, 0, 0),
                  child: Text(
                    '请选择反馈类型',
                    style: TextStyle(color: Color.fromRGBO(183, 183, 183, 1)),
                  ),
                ),
                Container(
                  child: Row(
                    children: <Widget>[
                      Radio(
                        value: 0,
                        onChanged: (v) {
                          setState(() {
                            this._groupValue = v;
                          });
                        },
                        activeColor: Colors.red,
                        groupValue: _groupValue,
                      ),
                      Text('功能吐槽'),
                      Radio(
                        value: 1,
                        onChanged: (v) {
                          setState(() {
                            this._groupValue = v;
                          });
                        },
                        activeColor: Colors.red,
                        groupValue: _groupValue,
                      ),
                      Text('系统吐槽'),
                      Radio(
                        value: 2,
                        onChanged: (v) {
                          setState(() {
                            this._groupValue = v;
                          });
                        },
                        activeColor: Colors.red,
                        groupValue: _groupValue,
                      ),
                      Text('内容意见')
                    ],
                  ),
                )
              ],
            ),
          ),
          Container(
            width: 330,
            margin: EdgeInsets.fromLTRB(10, 360, 0, 0),
            child: RaisedButton(
              color: Color.fromRGBO(196, 8, 8, 1),
              child: Text(
                '提交',
                style: TextStyle(color: Colors.white),
              ),
              onPressed: () {},
            ),
          )
        ],
      ),
      resizeToAvoidBottomInset:false,    //键盘弹框报超出
    );
  }
}
